package rolesystem.middle.managers;

import java.util.HashMap;
import java.util.Map;

public class BooleanManager
{
	/**
	 * The Map containing the booleans (value) and their name (Key).
	 */
	private static Map <String,Boolean> counterMap;
	
	/**
	 * Static constructor.
	 */
	static
	{
		counterMap=new HashMap<String,Boolean>();
	}
	
	public static synchronized void add(final String counterName)
	{
		counterMap.put(counterName, new Boolean(false));
	}
	
	public static synchronized void add(final String counterName, boolean counterValue)
	{
		counterMap.put(counterName, new Boolean(counterValue));
	}
	
	public static synchronized void set(final String counterName, boolean counterValue)
	{	
		if(counterMap.containsKey(counterName))
			counterMap.put(counterName,new Boolean(counterValue));
	}
	
	public static synchronized boolean get(final String counterName)
	{
		if(counterMap.containsKey(counterName))
			return counterMap.get(counterName).booleanValue();
		else
			return false;
	}
	
	public static synchronized void toggle(final String counterName)
	{
		if(counterMap.containsKey(counterName))
			counterMap.put(counterName,new Boolean(!counterMap.get(counterName).booleanValue()));
	}
	
	public static synchronized void reset(final String counterName)
	{
		if(counterMap.containsKey(counterName))
			counterMap.put(counterName,new Boolean(false));
	}
	
	public static synchronized boolean getAndSetIfFalse(final String counterName)
	{
		if(counterMap.containsKey(counterName))
		{
			if(counterMap.get(counterName).booleanValue()==false)
			{	
				counterMap.put(counterName,new Boolean(true));
				return false;
			}
			else
				return true;
		}	
		else 
			return false;	
	}
	
}
	
